import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
//静态加载 初始化看到的页面和框架
import Login from '@/views/login'
import Layout from '@/layout/Layout.vue'

//隐藏原地跳转错误
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

//配置路由地址 和 页面组件的一一对应关系
const routes = [
  /* 首页重定向 */
  {
    path: '/',
    redirect: '/login',
  },
  /* 登录 */
  {
    path: '/login',
    component: Login,
  },
  /* 首页 */
  {
    path: '/home',
    component: Layout, //框架
    meta : {path :'/home',title : '后台首页' },
    children: [
      {
        path: '',
        component: () => import('@/views/home'),
      },
    ],
  },
  /* 订单管理 */
  {
    path: '/order',
    component: Layout,
    meta : {path :'/order',title : '订单管理' },
    children: [
      {
        path: '',
        component: () => import('@/views/order'),
      },
    ],
  },
  /* 商品管理 */
  {
    path: '/goods',
    component: Layout,
    redirect: '/goods/goods-list',
    meta : {path :'/goods',title : '商品管理' },
    children: [
      {
        meta : {path :'/goods/goods-list',title : '商品列表' },
        path: 'goods-list', //不写斜杠相当于/goods/goods-list
        component: () => import('@/views/goods/goods-list'),
      },
      {
        meta : {path :'/goods/goods-add',title : '商品添加' },
        path: '/goods/goods-add',
        component: () => import('@/views/goods/goods-add'),
      },
      {
        meta : {path :'/goods/goods_cate',title : '商品分类' },
        path: '/goods/goods_cate',
        component: () => import('@/views/goods/goods_cate'),
      },
    ],
  },
  /* 店铺管理 */
  {
    path: '/shop',
    meta : {path :'/shop',title : '店铺管理' },
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/shop'),
      },
    ],
  },
  /* 账号管理 */
  {
    path: '/account',
    component: Layout,
    redirect: '/account/account-list',
    meta : {path :'/account',title : '账号管理' },
    children: [
      {
        meta : {path :'/account/account-list',title : '账号列表' },
        path: 'account-list',
        component: () => import('@/views/account/account-list'),
      },
      {
        meta : {path :'/account/account-add',title : '账号添加' },
        path: '/account/account-add',
        component: () => import('@/views/account/account-add'),
      },
      {
        meta : {path :'/account/account-add',title : '修改密码' },
        path: '/account/password-modify',
        component: () => import('@/views/account/password-modify'),
      },
      {
        meta : {path :'/account/account-person',title : '个人中心' },
        path: '/account/account-person',
        component: () => import('@/views/account/account-person'),
      },
    ],
  },
  /* 销售统计 */
  {
    path: '/total',
    component: Layout,
    redirect: '/total/total-goods',
    meta : {path :'/total',title : '销售统计' },
    children: [
      {
        meta : {path :'/total/tatal-goods',title : '订单统计' },
        path: '/total/tatal-goods',
        component: () => import('@/views/total/tatal-goods'),
      },
      {
        meta : {path :'/total/tatal-order',title : '订单统计' },
        path: '/total/tatal-order',
        component: () => import('@/views/total/tatal-order'),
      },
    ],
  },
]

const router = new VueRouter({
  routes,
})

export default router
